<?php

class m_keuangan extends CI_Model{
	
	function _list($data){
		extract($data);
		$sql = "SELECT 
					keuangan_ket,
					keuangan_id
				FROM m_keuangan
				WHERE 
					1 = 1 
		";
		
		if (@$keuangan_ket != "") $sql .= " AND keuangan_ket like '%".@$keuangan_ket."%'";
		
		$query = $this->db->query($sql);
		$records = $query->num_rows();
		
		$sql = "SELECT * FROM (".$sql.") k LIMIT ".(($page - 1) * $rows)." , ".$rows;
		$query = $this->db->query($sql);
		$result = $query->result();
		
		return '{ 
		  "total": "'.ceil($records / $rows).'", 
		  "page": "'.$page.'", 
		  "records": "'.$records .'",
		  "rows" : '.json_encode($result).'
		}';
	}
	
	function _insert($data){
		$this->db->insert('m_keuangan',$data);
		return 1;
	}
	
	function _update($data,$id){
		$this->db->where('keuangan_id',$id);
		$this->db->update('m_keuangan',$data);
		return 1;
	}
	
	function _delete($id){
		$this->db->where('keuangan_id',$id);
		$this->db->delete('m_keuangan');
		return 1;
	}
	
	function _deactivate($data,$id){
		$this->db->where('keuangan_id',$id);
		$this->db->update('m_keuangan',$data);
		return 1;
	}
}